package com.glodon.paas.job.model;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.glodon.paas.job.exception.JsonException;
import com.glodon.paas.job.util.JsonUtil;

@Entity
@Table(name = "global_status")
public class GlobalStatus {

    private String id = "global";

    private Map<String, String> values = new HashMap<String, String>();

    @Id
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getValue(String key) {
        Object value = values.get(key);
        return value == null ? "" : value.toString();
    }

    public String getJson() {
        return JsonUtil.mapToJson(values);
    }

    public void setJson(String json) throws JsonException {
        values = JsonUtil.jsonToMap(json);
    }

    @Transient
    public Map<String, String> getValues() {
        return values;
    }
}
